<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 主题展管理1 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <!-- <el-button
                    type="primary"
                    icon="el-icon-delete"
                    class="handle-del mr10"
                    @click="delAllSelection"
                >批量删除</el-button> -->
                会展名称:
                <el-input v-model="query.name" placeholder="会展名称" class="handle-input mr10" @change="handleSearch"></el-input>
                会展状态:
                <el-select v-model="query.type" placeholder="全部" class="handle-select mr10">
                    <el-option value="0" label="在展" key="0"></el-option>
                    <el-option value="1" label="不在展" key="1"></el-option>
                </el-select>
                开展时间: 从<el-input v-model="query.time1" class="handle-input mr11"></el-input>到
                <el-input v-model="query.time2" class="handle-input mr11"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <div class="add-more" style="display: block">
                    <el-button type="primary" @click="addExhibition">+ 新增主题</el-button>
                    <!-- <el-button  type="primary"  @click="addCompany"  >+ 管理参展公司</el-button> -->
                    <el-button type="primary" @click="addBaseTable">+ 新增软文</el-button>
                    <el-button type="primary" @click="addCompany">+ 新增参展公司</el-button>
                </div>
            </div>
            <el-table
                :data="tableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
                <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
                <!-- <el-table-column prop="id" label="ID" width="55" align="center"></el-table-column> -->
                <el-table-column prop="exhibitName" label="会展名称" align="center"></el-table-column>
                <el-table-column label="封面图" width="150" align="center">
                    <template slot-scope="scope">
                        <el-image
                            class="table-td-thumb"
                            :src="scope.row.exhibitImg"
                            :preview-src-list="[scope.row.authorHeadImg]"
                        ></el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="startTime" label="开展时间" width="180" align="center"></el-table-column>
                <el-table-column prop="endTime" label="闭展时间" width="180" align="center"></el-table-column>
                <!-- <el-table-column label="账户余额">
                    <template slot-scope="scope">￥{{scope.row.money}}</template>
                </el-table-column> -->
                <el-table-column prop="createTime" label="创建时间" width="180" align="center"></el-table-column>
                <el-table-column prop="exhibitStatus" label="当前状态" width="50" align="center">
                    <template slot-scope="scope">
                        <span v-if="scope.row.exhibitStatus == 0">在展</span>
                        <span v-else>结束</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="状态" align="center">
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'')"
                        >{{scope.row.state}}</el-tag>
                    </template>
                </el-table-column> -->

                <!-- <el-table-column prop="date" label="注册时间"></el-table-column> -->
                <el-table-column label="操作" width="500" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" @click="toDetail(scope.$index, scope.row)">查看参展公司</el-button>
                        <el-button type="success" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>
        <el-dialog title="在展公司" :visible.sync="exhibition_on" width="70%">
            <el-table
                :data="onExhibitonData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
                <!-- <el-table-column type="selection" width="55" align="center"></el-table-column> -->
                <!-- <el-table-column prop="id" label="ID" width="55" align="center"></el-table-column> -->
                <el-table-column prop="companyName" label="公司名称" align="center"></el-table-column>
                <el-table-column label="封面图" width="150" align="center">
                    <template slot-scope="scope">
                        <el-image
                            class="table-td-thumb1"
                            :src="scope.row.companyLogo"
                            :preview-src-list="[scope.row.companyLogo]"
                        ></el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="companyIntroduce" label="公司介绍" align="center"></el-table-column>
                <el-table-column prop="createTime" label="时间" width="180" align="center"></el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button @click="exhibition_on = false">取 消</el-button>
                <!-- <el-button type="primary" @click="saveEdit">确 定</el-button> -->
            </span>
        </el-dialog>
        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="会展名称">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="主题介绍">
                    <el-input v-model="form.address"></el-input>
                </el-form-item>
                <el-form-item label="开展时间">
                    <el-form-item label="日期时间">
                        <el-col :span="11">
                            <el-date-picker
                                type="date"
                                placeholder="选择日期"
                                v-model="form.date1"
                                value-format="yyyy-MM-dd"
                                style="width: 100%"
                            ></el-date-picker>
                        </el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%"></el-time-picker>
                        </el-col>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="结束时间">
                    <el-form-item label="日期时间">
                        <el-col :span="11">
                            <el-date-picker
                                type="date"
                                placeholder="选择日期"
                                v-model="form.date3"
                                value-format="yyyy-MM-dd"
                                style="width: 100%"
                            ></el-date-picker>
                        </el-col>
                        <el-col class="line" :span="2">-</el-col>
                        <el-col :span="11">
                            <el-time-picker placeholder="选择时间" v-model="form.date4" style="width: 100%"></el-time-picker>
                        </el-col>
                    </el-form-item>
                </el-form-item>
                主题展状态
                <el-select v-model="form.type" placeholder="全部" class="handle-select mr10">
                    <el-option value="0" label="在展" key="0"></el-option>
                    <el-option value="1" label="不在展" key="1"></el-option>
                </el-select>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>


        <!-- ----------------------------新增参展公司------------------------ -->
        <el-dialog title="新增参展公司" :visible.sync="addCompanyDialog" width="60%" @close='closeDialog'>
            <el-form>
                <el-form-item label="选择主题展">
                    <el-select placeholder="请选择主题展" v-model="exhibitBasicId" @change="exhibitBasicListChange">
                        <el-option v-for="(item, index) in exhibitBasicList" :key="index" :label="item.value" :value="item.id"> </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="选择公司">
                    <div class="tableBox">
                        搜索未参展公司: <el-input class="w600" v-model="searchCompanyName" @change="getAddCompanyList"></el-input> 
                        <el-button type="primary" @click="getAddCompanyList"> 搜索 </el-button>
                         <br />
                        <br />
                        <el-table :data="addCompanyTableData" highlight-current-row style="width: 100%">
                            <el-table-column type="index" label="序号" width="50"> </el-table-column>
                            <el-table-column prop="companyName" label="公司名"> </el-table-column>
                            <el-table-column label="公司LOGO">
                                <template slot-scope="scope">
                                    <img :src="$myUrl.IMGURL + scope.row.companyLogo" alt="" style="width: 50px; height: 50px" />
                                </template>
                            </el-table-column>
                            <el-table-column label="操作">
                                <template slot-scope="scope">
                                    <el-button type="primary" @click="companyOnsubmit(scope.$index, scope.row)">提交</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-form-item>
                <!-- <el-form-item label="是否推荐">
                    <el-radio-group v-model="isRecommend">
                        <el-radio :label="0">是</el-radio>
                        <el-radio :label="1">否</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="权重值">
                    <el-input placeholder="请输入权重值" class="w600" v-model="orderLevel"></el-input> &nbsp;
                </el-form-item> -->
                <el-form-item label="">
                    <el-table :data="onsubmitTableData" style="width: 100%">
                        <el-table-column type="index" label="序号" width="50"> </el-table-column>
                        <el-table-column prop="companyName" label="公司名"> </el-table-column>
                        <el-table-column label="公司LOGO">
                            <template slot-scope="scope">
                                <img :src="$myUrl.IMGURL + scope.row.companyLogo" alt="" style="width: 50px; height: 50px" />
                            </template>
                        </el-table-column>
                        <el-table-column label="是否推荐">
                            <template slot-scope="scope">
                                <span v-if="scope.row.isHot == 0">是</span>
                                <span v-if="scope.row.isHot == 1">否</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="权重">
                            <template slot-scope="scope">
                                <!-- <span v-if="scope.row.orderLevel == ''">/</span> -->
                                <span >{{ scope.row.orderLevel }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button type="primary" @click="aaa(scope.$index, scope.row)">修改推荐</el-button>
                                <el-button type="danger"  @click="tableDetele(scope.$index, scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form-item>
                <el-form-item label=""></el-form-item>
                <el-form-item label=""></el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addCompanyDialog = false">取 消</el-button>
                <el-button type="primary" @click="addCompanyOnsubmit">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import axios from 'axios';
//import { fetchData } from '../../api/index';
export default {
    name: 'basetable',
    data() {
        return {
            query: {
                type: '',
                name: '',
                pageIndex: 1,
                pageSize: 10,
                time1: '',
                time2: ''
            },
            searchData: [],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            exhibition_on: false,
            pageTotal: 1,
            form: {},
            onExhibitonData: [],
            idx: -1,
            id: -1,
            //
            addCompanyDialog: false,
            exhibitionId: '',
            isRecommend: 1,
            orderLevel: '',
            searchCompanyName:'',
            // 没有参展的公司表单列表
            addCompanyTableData: [],
            // 提交的表单
            onsubmitTableData: [],

            // 已参展的公司列表
            exhibitBasicList: [],

            exhibitBasicId: ''
        };
    },
    created() {
        this.getData();
        this.getExhibitBasicList();
    },
    methods: {
        toDetail(index, row) {
            //this.$router.push('/exhibition-detail');
            this.exhibition_on = true;
            //console.log(index)
            //console.log(row)
            axios.get(this.$myUrl.BASEURL + 'exhibit/getExhibitCompanyListInfo?exhibitId=' + row.id + '&showCompanyType=0').then((res) => {
                //console.log(res)
                this.onExhibitonData = res.data.data;
                this.onExhibitonData.forEach((item, index) => {
                    ////console.log(item)
                    item.companyLogo = this.$myUrl.IMGURL + item.companyLogo;
                });
            });
        },
        // 获取 easy-mock 的模拟数据  exhibit/getExhibitCompanyList
        getData() {
            axios.get(this.$myUrl.BASEURL + 'exhibit/getExhibitList?pageNum=0&pageSize=0').then((res) => {
                //console.log(res);
                this.tableData = res.data.data;
                this.pageTotal = res.data.totalNumber;
                //this.pageTotal = res.pageTotal ;
                this.tableData.forEach((item, index) => {
                    ////console.log(item)
                    item.exhibitImg = this.$myUrl.IMGURL + item.exhibitImg;
                });
            });
        },
        // 主题展下拉框数据
        getExhibitBasicList() {
            axios.get(this.$myUrl.BASEURL + 'exhibit/getExhibitBasicList').then((res) => {
                console.log('主题展下拉框数据', res);
                this.exhibitBasicList = res.data.data;
            });
        },
        // 触发搜索按钮
        handleSearch() {
            this.$set(this.query, 'pageIndex', 1);
            this.tableData = [];
            this.searchData = [];
            axios.get(this.$myUrl.BASEURL + 'exhibit/getExhibitList?pageNum=0&pageSize=0&exhibitName=' + this.query.name).then((res) => {
                //console.log(res)
                res.data.data.forEach((item, index) => {
                    item.exhibitImg = this.$myUrl.IMGURL + item.exhibitImg;
                    this.tableData.push(item);
                });
            });
        },
        // 删除操作
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$message.success('删除成功');
                    this.tableData.splice(index, 1);
                })
                .catch(() => {});
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        delAllSelection() {
            const length = this.multipleSelection.length;
            let str = '';
            this.delList = this.delList.concat(this.multipleSelection);
            for (let i = 0; i < length; i++) {
                str += this.multipleSelection[i].name + ' ';
            }
            this.$message.error(`删除了${str}`);
            this.multipleSelection = [];
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveEdit() {
            //console.log(this.form)
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        },
        //
        exhibitBasicListChange() {
            this.getAddCompanyList();
        },
        // 获取新增会展公司列表api
        getAddCompanyList() {
            axios
                .get(this.$myUrl.BASEURL + 'exhibit/getExhibitCompanyListInfo?showCompanyType=' + 1 + '&exhibitId=' + this.exhibitBasicId + '&companyName=' + this.searchCompanyName)
                .then((res) => {
                    console.log('会展公司列表', res);
                    this.addCompanyTableData = res.data.data;
                });
        },
        // 未添加公司提交按钮
        companyOnsubmit(index, row) {
            row.isHot = 1;
            row.orderLevel = 0;

            console.log(row);
            // 判断是否重复
            let isRepeat = false;
            this.onsubmitTableData.forEach((item) => {
                if (item.companyId == row.companyId) {
                    isRepeat = true;
                }
            });
            if (isRepeat) {
                this.$message.error('该公司已重复');
            } else {
                this.onsubmitTableData.push(row);
            }

            this.orderLevel = '';
        },
        // 新增是修改推荐按钮
        aaa(index, row){
          console.log(row);
         if ( row.isHot == 0) {
              this.$set(this.onsubmitTableData[index],this.onsubmitTableData[index].isHot, 1)
         } else {
              this.$set(this.onsubmitTableData[index],this.onsubmitTableData[index].isHot, 0)
         }
          console.log(row);
        //   console.log('old',this.onsubmitTableData[0]);
        //   if (row.isHot == 1) {
        //  this.$set()
        //  this.onsubmitTableData[0].isHot = 1
        //   console.log('new',this.onsubmitTableData[0]);

        //       this.$set(this.onsubmitTableData[index],isHot, 0)

        //   } else {
        //     //   this.onsubmitTableData[index].isHot = 1
        //        this.$set(this.onsubmitTableData[index],isHot, 1)
        //   }
        //   console.log(this.onsubmitTableData);
        },
        tableDetele(index, row){
          this.onsubmitTableData.splice(index,1)
        },
        // 新增主题展按钮
        addCompany(index, row) {
            this.addCompanyDialog = true;
        },

        // 新增主题展提交
        addCompanyOnsubmit() {
            axios.post(this.$myUrl.BASEURL + 'exhibit/addExhibitCompanyBatch', {
                exhibitId: this.exhibitBasicId,
                exhibitCompanyList: this.onsubmitTableData
            }).then( res => {
                console.log(res);
                if (res.data.code == 200) {
                    this.$message.success('新增成功')
                    this.addCompanyDialog = false
                } else {
                    this.$message.error(res.data.msg)
                }
            })
        },

        addExhibition() {
            this.$router.push({
                path: '/exhibition-add'
            });
        },
        addBaseTable() {
            this.$router.push({
                path: '/content-detail'
            });
        },
        // 关闭弹窗
        closeDialog(){
            // 没有参展的公司表单列表
            this.addCompanyTableData =[]
            // 提交的表单
            this.onsubmitTableData= []
            this.exhibitBasicId = ''
            this.searchCompanyName = ''
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.mr11 {
    width: 100px;
    margin: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
    /* border-radius: 50%; */
}
.table-td-thumb1 {
    height: 80px;
}
.w600 {
    width: 600px;
}
.tableBox {
    border: 1px solid #ccc;
    height: 300px;
    overflow: auto;
    padding: 10px;
    box-sizing: border-box;
}

.element.style /deep/ {
    width: 80%;
    border: 1px solid red;
}
</style>
